package com.tcm.doctor.web.controller;

import com.base.core.utils.R;
import com.tcm.item.domain.entity.DosageForm;
import com.tcm.item.service.drugs.DosageFormService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;


@Slf4j
@Api(value = "dosage", tags = "药品剂型接口")
@RequestMapping("/doctor")
@RestController
public class DosageFormController {

    @DubboReference(version = "0.0.1-alpha", timeout = 3000, check = false, retries = 3)
    private DosageFormService dosageFormService;

    @GetMapping("/dosageform/list")
    public R list() throws Exception {
        return R.success(dosageFormService.findDosageFormList());
    }

    @PostMapping("/dosageform/save")
    public R save(@RequestBody DosageForm dosageForm) {
        try{
            dosageFormService.save(dosageForm);
        }catch (Exception e){
            R.fail(e.getMessage());
        }
        return R.success();
    }

    @PostMapping("/dosageform/update")
    public R update(@RequestBody DosageForm dosageForm) {
        int result = dosageFormService.update(dosageForm);
        if(result > 0){
            return R.success();
        }
        return R.fail("更新失败");
    }

    @GetMapping("/dosageform/delete")
    public R delete(@RequestParam("id") Long id) {
        int result = dosageFormService.deleteLogicById(id);
        if(result > 0){
            return R.success();
        }
        return R.fail("更新失败");
    }
}
